home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-25 | 5.8 KB | 119 lines | [TEXT/CCL ] |
- ; (c) Copyright 1990 by University of Massachusetts. All rights reserved.
- ; This software was conceived, designed, and written by Dan Suthers
- ; while supported by the National Science Foundation under grant number
- ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
- ; CA. Partial support was also received from the Office of Naval Research
- ; under a University Research Initiative Grant, contract N00014-86-K-0764.
- ; Mr. Suthers created this software under his own initiative while in an
- ; academic relationship with the University of Massachusetts. The above
- ; copyright notice was a condition placed by University lawyers on approval
- ; of distribution of this software by Apple Computer, and is not meant to
- ; imply that this software was created in an employment or "work for hire"
- ; relationship between the University and Mr. Suthers.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; File: COMPARE.lisp
- ; Author: Dan Suthers
- ; Created: 16-Jun-88 10:42:08
- ; Modified: 22-Jun-90 02:08:45 (Dan Suthers)
- ; Language: Common Lisp
- ; Package: UTILS
- ;
- ; Description: Alternate comparison functions (eg more lenient EQUAL).
- ;
- ; (c) Copyright 1988, by Daniel D. Suthers
- ; Department of Computer and Information Science
- ; University of Massachusetts
- ; Amherst, Massachusetts 01003
- ;
- ; This software was conceived, designed, and written by Dan Suthers
- ; while supported by the National Science Foundation under grant number
- ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
- ; CA. Partial support was also received from the Office of Naval Research
- ; under a University Research Initiative Grant, contract N00014-86-K-0764.
- ; I wish to acknowledge the generous support of Beverly Woolf, who obtained
- ; the above grants and encouraged me to pursue my own research interests in
- ; her lab. This work would not have been possible without the resources and
- ; stimulating environment of the Computer and Information Science department.
- ;
- ; Permission to use, modify, and distribute this software is granted subject
- ; to the following restrictions and understandings:
- ; 1. The file header, including this notice, shall be retained, and may be
- ; extended to include documentation of modifications to the software.
- ; 2. This material is for nonprofit educational and research purposes only.
- ; Users are requested, but not required, to inform Mr. Suthers of any
- ; noteworthy uses of this software.
- ; 3. Mr. Suthers and the University of Massachusetts make no warrantee or
- ; representation that the operation of this software will be error free,
- ; and are under no obligation to provide any services.
- ; 4. Any user of such software agrees to indemnify and hold harmless Mr.
- ; Suthers and the University of Massachusetts from all claims arising
- ; out of the use or misuse of this software, or arising out of any
- ; accident, injury, or damage whatsoever, and from all costs, counsel
- ; fees, and liabilities incurred in or about any such claim, action, or
- ; proceeding brought thereon.
- ; 5. All materials and reports developed as a consequence of the use of
- ; this software shall duly acknowledge such use, in accordance with
- ; the usual standards of acknowledging credit in academic research.
- ;
- ; Status: Done and tested.
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (in-package :UTILS)
-
- (export '(
- alike
- orderp
- ))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun ALIKE (x y)
- "alike <x> <y> [Function]
- A more permissive equality test:
- - Floats numeric arguments.
- - Ignores packages when comparing atoms.
- - Ignores case when comparing strings.
- - Compares atoms of different types by converting to print names.
- - Recursively applies the above to lists.
- - Defaults to EQUALP if an argument is not an atom or list."
- (cond ((and (numberp x) (numberp y)) (= (float x) (float y)))
- ((and (atom x) (atom y))
- (string-equal
- (if (numberp x) (princ-to-string x) (string x))
- (if (numberp y) (princ-to-string y) (string y)) ))
- ((and (consp x) (consp y))
- (and (alike (first x) (first y))
- (alike (rest x) (rest y)) ))
- ((equalp x y)) ))
-
- (defun ORDERP (x y)
- "orderp <x> <y> [Function]
- Defines a lexical ordering on a variety of LISP objects:
- - Numbers are floated before comparing to each other.
- - Case is ignored in strings.
- - Atoms are compared by printname (ignores packages).
- - Mixtures of Atoms, Strings, and Numbers are compared by
- print names, using the above conventions.
- - Lists are compared lexically (element wise & recursively);
- - Lists are always 'greater than' atomic types.
- Always returns NIL if given any other type. See also ALIKE."
- (cond ((and (numberp x) (numberp y)) ; printnames don't work here!
- (< x y))
- ((and (atom x) (atom y)) ; compare atomic types by printnames
- (string-lessp
- (if (numberp x) (princ-to-string (float x)) (string x))
- (if (numberp y) (princ-to-string (float y)) (string y)) ))
- ((and (consp x) (consp y)) ; compare lists lexically by elements
- (cond ((orderp (first x) (first y)) T)
- ((alike (first x) (first y))
- (orderp (rest x) (rest y)) )
- (T NIL)))
- ((and (atom x) (consp y)) T) ; atomic types less than lists
- (T NIL))) ; cannot compare
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (provide :COMPARE)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; EOF
-